package ${packageName}.dto;

import java.io.Serializable;
import java.util.List;

import com.swak.security.Principal;
import com.swak.utils.Lists;
import com.swak.entity.Page;
import com.swak.persistence.Classify;
import com.swak.utils.bean.BeanCopier;
import com.swak.utils.bean.BeanCopiers;

<#if table.isHasDate>
import com.alibaba.fastjson.annotation.JSONField;
import com.swak.Constants;
</#if>
import com.swak.annotation.ApiDoc;
import ${packageName}.entity.${className};

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * ${className}DTO.
 * 
 * @author Auto Generator
 * @date ${date}
 */
@Getter
@Setter
@Accessors(chain = true)
public class ${className}DTO implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@lombok.EqualsAndHashCode.Exclude
	@lombok.ToString.Exclude
	private static final transient BeanCopier<${className}DTO, ${className}> Copier = BeanCopiers.create(${className}DTO.class, 
	        ${className}.class);
	
	<#-- 生成字段属性 -->
	<#list table.columns as c>
	<#if c.isDateColumn && !c.isDelFlagColumn>
	@ApiDoc(value = "${c.comments}")
	@JSONField(format = Constants.Second_Format)
	private ${c.javaType} ${c.javaField}; // ${c.comments}
	<#elseif !c.isDelFlagColumn>
	@ApiDoc(value = "${c.comments}")
	private ${c.javaType} ${c.javaField}; // ${c.comments}
	</#if>
	</#list>
	
	/**
	 * 操作人的身份
	 */
	private Principal principal;
	
	/**
	 * DTO 转换为 PO
	 *
	 * @param entity
	 * @return DTO
	 */
	public ${className} transform() {
		return Copier.transform(this);
	}
	
	/**
	 * DTOS 转换为 POS
	 *
	 * @param dtos
	 * @return DTOs
	 */
	public static List<${className}> transform(List<${className}DTO> dtos) {
	    List<${className}> pos = Lists.newArrayList();
	    if (dtos == null) { return pos;}
	    for (${className}DTO dto: dtos) {
	    	pos.add(dto.transform());
	    }
		return pos;
	}
	
	/**
	 * PO 转换为 DTO
	 *
	 * @param entity
	 * @return DTO
	 */
	public static ${className}DTO convert(${className} entity) {
	    if (entity == null) { return null;}
		return Copier.convert(entity);
	}
	
	/**
	 * POS 转换为 DTOS
	 *
	 * @param entitys
	 * @return DTOs
	 */
	public static List<${className}DTO> convert(List<${className}> entitys) {
	    List<${className}DTO> dtos = Lists.newArrayList();
	    if (entitys == null) { return dtos;}
	    for (${className} entity: entitys) {
	    	dtos.add(${className}DTO.convert(entity));
	    }
		return dtos;
	}
	
	/**
	 * Page 转换为 Page
	 *
	 * @param entity
	 * @return DTO
	 */
	public static Page<${className}DTO> convert(Page<${className}> page) {
		return Page.of(page.getParam(), ${className}DTO.convert(page.getData()));
	}
	
	/**
	 * classify 分类
	 *
	 * @param dtos
	 * @param pos
	 * @return Classify
	 */
	public static Classify<${className}> classify(List<${className}DTO> dtos, List<${className}> pos) {
		return Classify.of(${className}DTO.transform(dtos), pos);
	}
	
	/**
	 * 创建DTO
	 *
	 * @return DTO
	 */
	public static ${className}DTO of() {
	    return new ${className}DTO();
	}
}